package com.atguigu.threadtest;

import java.util.concurrent.locks.ReentrantLock;

/**
 * ClassName: ReentrancyLock
 * Package: com.atguigu
 * Description:
 *
 * @author: fu-wang
 * @create: 2024/10/28 19:02
 * version: 1.0
 */
public class ReentrancyLock {
    private final ReentrantLock lock = new ReentrantLock();
    public void t1(){
        lock.lock();
        this.t2();
        System.out.println(Thread.currentThread().getName()+" t1");
        lock.unlock();
    }
    public synchronized void t2(){
        System.out.println(Thread.currentThread().getName()+" t2");
    }
    public synchronized void t3(){
        new ReentrancyLock().t1();
        System.out.println(Thread.currentThread().getName()+" t3");
    }
}
class ReenTest{
    public static void main(String[] args) {
        ReentrancyLock reentrancyLock = new ReentrancyLock();
        new Thread(()->{
            reentrancyLock.t1();
                    },"thread t1").start();
        new Thread(()->{
            reentrancyLock.t2();
        },"thread t2").start();
        new Thread(()->{
            reentrancyLock.t3();
        },"thread t3").start();
    }
}
